/*
 * Copyright (C) 2007-2018 Siemens AG
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

/*******************************************************************
 *
 * @author Daniel.Peintner.EXT@siemens.com
 * @version 0.9.4 
 * @contact Richard.Kuntschke@siemens.com
 *
 * <p>Code generated by EXIdizer</p>
 * <p>Schema: xmldsig-core-schema.xsd</p>
 *
 *
 ********************************************************************/




#include "xmldsigEXIDatatypesEncoder.h"

#include "EncoderChannel.h"
#include "EXIHeaderEncoder.h"

#include "xmldsigEXIDatatypes.h"
#include "ErrorCodes.h"

#ifndef EXI_xmldsig_DATATYPES_ENCODER_C
#define EXI_xmldsig_DATATYPES_ENCODER_C

#if DEPLOY_XMLDSIG_CODEC == SUPPORT_YES

static int errn;

/* Forward Declarations */
static int encode_xmldsigCanonicalizationMethodType(bitstream_t* stream, struct xmldsigCanonicalizationMethodType* xmldsigCanonicalizationMethodType);
static int encode_xmldsigManifestType(bitstream_t* stream, struct xmldsigManifestType* xmldsigManifestType);
static int encode_xmldsigObjectType(bitstream_t* stream, struct xmldsigObjectType* xmldsigObjectType);
static int encode_xmldsigTransformType(bitstream_t* stream, struct xmldsigTransformType* xmldsigTransformType);
static int encode_xmldsigSignatureMethodType(bitstream_t* stream, struct xmldsigSignatureMethodType* xmldsigSignatureMethodType);
static int encode_xmldsigDigestMethodType(bitstream_t* stream, struct xmldsigDigestMethodType* xmldsigDigestMethodType);
static int encode_xmldsigRetrievalMethodType(bitstream_t* stream, struct xmldsigRetrievalMethodType* xmldsigRetrievalMethodType);
static int encode_xmldsigSignatureValueType(bitstream_t* stream, struct xmldsigSignatureValueType* xmldsigSignatureValueType);
static int encode_xmldsigX509IssuerSerialType(bitstream_t* stream, struct xmldsigX509IssuerSerialType* xmldsigX509IssuerSerialType);
static int encode_xmldsigSignedInfoType(bitstream_t* stream, struct xmldsigSignedInfoType* xmldsigSignedInfoType);
static int encode_xmldsigSignaturePropertiesType(bitstream_t* stream, struct xmldsigSignaturePropertiesType* xmldsigSignaturePropertiesType);
static int encode_xmldsigSignaturePropertyType(bitstream_t* stream, struct xmldsigSignaturePropertyType* xmldsigSignaturePropertyType);
static int encode_xmldsigKeyValueType(bitstream_t* stream, struct xmldsigKeyValueType* xmldsigKeyValueType);
static int encode_xmldsigRSAKeyValueType(bitstream_t* stream, struct xmldsigRSAKeyValueType* xmldsigRSAKeyValueType);
static int encode_xmldsigPGPDataType(bitstream_t* stream, struct xmldsigPGPDataType* xmldsigPGPDataType);
static int encode_xmldsigTransformsType(bitstream_t* stream, struct xmldsigTransformsType* xmldsigTransformsType);
static int encode_xmldsigX509DataType(bitstream_t* stream, struct xmldsigX509DataType* xmldsigX509DataType);
static int encode_xmldsigSignatureType(bitstream_t* stream, struct xmldsigSignatureType* xmldsigSignatureType);
static int encode_xmldsigDSAKeyValueType(bitstream_t* stream, struct xmldsigDSAKeyValueType* xmldsigDSAKeyValueType);
static int encode_xmldsigReferenceType(bitstream_t* stream, struct xmldsigReferenceType* xmldsigReferenceType);
static int encode_xmldsigSPKIDataType(bitstream_t* stream, struct xmldsigSPKIDataType* xmldsigSPKIDataType);
static int encode_xmldsigKeyInfoType(bitstream_t* stream, struct xmldsigKeyInfoType* xmldsigKeyInfoType);


/* Complex type name='http://www.w3.org/2000/09/xmldsig#,CanonicalizationMethodType',  base type name='anyType',  content type='MIXED',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  particle='((WC[##any]){0-UNBOUNDED})',  derivedBy='RESTRICTION'.  */
static int encode_xmldsigCanonicalizationMethodType(bitstream_t* stream, struct xmldsigCanonicalizationMethodType* xmldsigCanonicalizationMethodType) {
	int grammarID = 0;
	int done = 0;
	int wcDone = 0;
	
	
	while(!done) {
		switch(grammarID) {
		case 0:
			/* FirstStartTag[ATTRIBUTE[STRING](Algorithm)] */
			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigCanonicalizationMethodType->Algorithm.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigCanonicalizationMethodType->Algorithm.characters, xmldsigCanonicalizationMethodType->Algorithm.charactersLen);
					}
				}
				grammarID = 1;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 1:
			/* StartTag[START_ELEMENT_GENERIC, END_ELEMENT, CHARACTERS_GENERIC[STRING]] */
			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 2;
			} else 			if ( xmldsigCanonicalizationMethodType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else 			if ( xmldsigCanonicalizationMethodType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 2);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigCanonicalizationMethodType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigCanonicalizationMethodType->ANY.characters, xmldsigCanonicalizationMethodType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 2;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 2:
			/* Element[START_ELEMENT_GENERIC, END_ELEMENT, CHARACTERS_GENERIC[STRING]] */
			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 2;
			} else 			if ( xmldsigCanonicalizationMethodType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else 			if ( xmldsigCanonicalizationMethodType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 2);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigCanonicalizationMethodType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigCanonicalizationMethodType->ANY.characters, xmldsigCanonicalizationMethodType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 2;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}

/* Complex type name='http://www.w3.org/2000/09/xmldsig#,ManifestType',  base type name='anyType',  content type='ELEMENT',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  particle='("http://www.w3.org/2000/09/xmldsig#":Reference{1-UNBOUNDED})',  derivedBy='RESTRICTION'.  */
static int encode_xmldsigManifestType(bitstream_t* stream, struct xmldsigManifestType* xmldsigManifestType) {
	int grammarID = 4;
	int done = 0;
	
	unsigned int xmldsigManifestType_Reference_currArrayIndex = 0;
	
	while(!done) {
		switch(grammarID) {
		case 4:
			/* FirstStartTag[ATTRIBUTE[STRING](Id), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Reference)] */
			if ( xmldsigManifestType->Id_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigManifestType->Id.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigManifestType->Id.characters, xmldsigManifestType->Id.charactersLen);
					}
				}
				grammarID = 5;
			} else 			if (xmldsigManifestType_Reference_currArrayIndex < xmldsigManifestType->Reference.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					errn = encode_xmldsigReferenceType(stream, &xmldsigManifestType->Reference.array [xmldsigManifestType_Reference_currArrayIndex++]);
				}
				grammarID = 6;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 5:
			/* StartTag[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Reference)] */
			if (xmldsigManifestType_Reference_currArrayIndex < xmldsigManifestType->Reference.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encode_xmldsigReferenceType(stream, &xmldsigManifestType->Reference.array [xmldsigManifestType_Reference_currArrayIndex++]);
				}
				grammarID = 6;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 6:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Reference), END_ELEMENT] */
			if (xmldsigManifestType_Reference_currArrayIndex < xmldsigManifestType->Reference.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					errn = encode_xmldsigReferenceType(stream, &xmldsigManifestType->Reference.array [xmldsigManifestType_Reference_currArrayIndex++]);
				}
				grammarID = 6;
			} else 			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}

/* Complex type name='http://www.w3.org/2000/09/xmldsig#,ObjectType',  base type name='anyType',  content type='MIXED',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  particle='((WC[##any])){0-UNBOUNDED}',  derivedBy='RESTRICTION'.  */
static int encode_xmldsigObjectType(bitstream_t* stream, struct xmldsigObjectType* xmldsigObjectType) {
	int grammarID = 7;
	int done = 0;
	int wcDone = 0;
	
	
	while(!done) {
		switch(grammarID) {
		case 7:
			/* FirstStartTag[ATTRIBUTE[STRING](Encoding), ATTRIBUTE[STRING](Id), ATTRIBUTE[STRING](MimeType), START_ELEMENT_GENERIC, END_ELEMENT, CHARACTERS_GENERIC[STRING]] */
			if ( xmldsigObjectType->Encoding_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigObjectType->Encoding.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigObjectType->Encoding.characters, xmldsigObjectType->Encoding.charactersLen);
					}
				}
				grammarID = 8;
			} else 			if ( xmldsigObjectType->Id_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 1);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigObjectType->Id.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigObjectType->Id.characters, xmldsigObjectType->Id.charactersLen);
					}
				}
				grammarID = 9;
			} else 			if ( xmldsigObjectType->MimeType_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 2);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigObjectType->MimeType.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigObjectType->MimeType.characters, xmldsigObjectType->MimeType.charactersLen);
					}
				}
				grammarID = 1;
			} else 			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 2;
			} else 			if ( xmldsigObjectType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 4);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else 			if ( xmldsigObjectType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 5);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigObjectType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigObjectType->ANY.characters, xmldsigObjectType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 2;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 8:
			/* StartTag[ATTRIBUTE[STRING](Id), ATTRIBUTE[STRING](MimeType), START_ELEMENT_GENERIC, END_ELEMENT, CHARACTERS_GENERIC[STRING]] */
			if ( xmldsigObjectType->Id_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigObjectType->Id.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigObjectType->Id.characters, xmldsigObjectType->Id.charactersLen);
					}
				}
				grammarID = 9;
			} else 			if ( xmldsigObjectType->MimeType_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 1);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigObjectType->MimeType.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigObjectType->MimeType.characters, xmldsigObjectType->MimeType.charactersLen);
					}
				}
				grammarID = 1;
			} else 			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 2;
			} else 			if ( xmldsigObjectType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 3);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else 			if ( xmldsigObjectType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 4);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigObjectType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigObjectType->ANY.characters, xmldsigObjectType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 2;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 9:
			/* StartTag[ATTRIBUTE[STRING](MimeType), START_ELEMENT_GENERIC, END_ELEMENT, CHARACTERS_GENERIC[STRING]] */
			if ( xmldsigObjectType->MimeType_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigObjectType->MimeType.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigObjectType->MimeType.characters, xmldsigObjectType->MimeType.charactersLen);
					}
				}
				grammarID = 1;
			} else 			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 2;
			} else 			if ( xmldsigObjectType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 2);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else 			if ( xmldsigObjectType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 3);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigObjectType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigObjectType->ANY.characters, xmldsigObjectType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 2;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 1:
			/* StartTag[START_ELEMENT_GENERIC, END_ELEMENT, CHARACTERS_GENERIC[STRING]] */
			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 2;
			} else 			if ( xmldsigObjectType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else 			if ( xmldsigObjectType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 2);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigObjectType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigObjectType->ANY.characters, xmldsigObjectType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 2;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 2:
			/* Element[START_ELEMENT_GENERIC, END_ELEMENT, CHARACTERS_GENERIC[STRING]] */
			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 2;
			} else 			if ( xmldsigObjectType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else 			if ( xmldsigObjectType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 2);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigObjectType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigObjectType->ANY.characters, xmldsigObjectType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 2;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}

/* Complex type name='http://www.w3.org/2000/09/xmldsig#,TransformType',  base type name='anyType',  content type='MIXED',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  particle='((WC[##other:"http://www.w3.org/2000/09/xmldsig#"])|"http://www.w3.org/2000/09/xmldsig#":XPath){0-UNBOUNDED}',  derivedBy='RESTRICTION'.  */
static int encode_xmldsigTransformType(bitstream_t* stream, struct xmldsigTransformType* xmldsigTransformType) {
	int grammarID = 10;
	int done = 0;
	int wcDone = 0;
	
	unsigned int xmldsigTransformType_XPath_currArrayIndex = 0;
	
	while(!done) {
		switch(grammarID) {
		case 10:
			/* FirstStartTag[ATTRIBUTE[STRING](Algorithm)] */
			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigTransformType->Algorithm.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigTransformType->Algorithm.characters, xmldsigTransformType->Algorithm.charactersLen);
					}
				}
				grammarID = 11;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 11:
			/* StartTag[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}XPath), START_ELEMENT_GENERIC, END_ELEMENT, CHARACTERS_GENERIC[STRING]] */
			if (xmldsigTransformType_XPath_currArrayIndex < xmldsigTransformType->XPath.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 0);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[STRING]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						/* encode string as string table miss (+2 len)*/
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigTransformType->XPath.array[xmldsigTransformType_XPath_currArrayIndex].charactersLen + 2));
						if (errn == 0) {
							errn = encodeCharacters(stream, xmldsigTransformType->XPath.array[xmldsigTransformType_XPath_currArrayIndex].characters, xmldsigTransformType->XPath.array[xmldsigTransformType_XPath_currArrayIndex].charactersLen);
							xmldsigTransformType_XPath_currArrayIndex++;
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 12;
			} else 			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 12;
			} else 			if ( xmldsigTransformType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 2);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else 			if ( xmldsigTransformType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 3);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigTransformType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigTransformType->ANY.characters, xmldsigTransformType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 12;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 12:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}XPath), START_ELEMENT_GENERIC, END_ELEMENT, CHARACTERS_GENERIC[STRING]] */
			if (xmldsigTransformType_XPath_currArrayIndex < xmldsigTransformType->XPath.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 0);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[STRING]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						/* encode string as string table miss (+2 len)*/
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigTransformType->XPath.array[xmldsigTransformType_XPath_currArrayIndex].charactersLen + 2));
						if (errn == 0) {
							errn = encodeCharacters(stream, xmldsigTransformType->XPath.array[xmldsigTransformType_XPath_currArrayIndex].characters, xmldsigTransformType->XPath.array[xmldsigTransformType_XPath_currArrayIndex].charactersLen);
							xmldsigTransformType_XPath_currArrayIndex++;
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 12;
			} else 			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 12;
			} else 			if ( xmldsigTransformType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 2);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else 			if ( xmldsigTransformType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 3);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigTransformType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigTransformType->ANY.characters, xmldsigTransformType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 12;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}

/* Complex type name='http://www.w3.org/2000/09/xmldsig#,SignatureMethodType',  base type name='anyType',  content type='MIXED',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  particle='("http://www.w3.org/2000/09/xmldsig#":HMACOutputLength{0-1},(WC[##other:"http://www.w3.org/2000/09/xmldsig#"]){0-UNBOUNDED})',  derivedBy='RESTRICTION'.  */
static int encode_xmldsigSignatureMethodType(bitstream_t* stream, struct xmldsigSignatureMethodType* xmldsigSignatureMethodType) {
	int grammarID = 13;
	int done = 0;
	int wcDone = 0;
	
	
	while(!done) {
		switch(grammarID) {
		case 13:
			/* FirstStartTag[ATTRIBUTE[STRING](Algorithm)] */
			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigSignatureMethodType->Algorithm.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigSignatureMethodType->Algorithm.characters, xmldsigSignatureMethodType->Algorithm.charactersLen);
					}
				}
				grammarID = 14;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 14:
			/* StartTag[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}HMACOutputLength), START_ELEMENT_GENERIC, END_ELEMENT, CHARACTERS_GENERIC[STRING]] */
			if ( xmldsigSignatureMethodType->HMACOutputLength_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 0);
				if(errn == 0) {
					/* FirstStartTag[CHARACTERS[INTEGER]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeInteger64(stream, xmldsigSignatureMethodType->HMACOutputLength);
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 2;
			} else 			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 2;
			} else 			if ( xmldsigSignatureMethodType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 2);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else 			if ( xmldsigSignatureMethodType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 3);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigSignatureMethodType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigSignatureMethodType->ANY.characters, xmldsigSignatureMethodType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 15;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 2:
			/* Element[START_ELEMENT_GENERIC, END_ELEMENT, CHARACTERS_GENERIC[STRING]] */
			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 2;
			} else 			if ( xmldsigSignatureMethodType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else 			if ( xmldsigSignatureMethodType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 2);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigSignatureMethodType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigSignatureMethodType->ANY.characters, xmldsigSignatureMethodType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 2;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 15:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}HMACOutputLength), START_ELEMENT_GENERIC, END_ELEMENT, CHARACTERS_GENERIC[STRING]] */
			if ( xmldsigSignatureMethodType->HMACOutputLength_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 0);
				if(errn == 0) {
					/* FirstStartTag[CHARACTERS[INTEGER]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeInteger64(stream, xmldsigSignatureMethodType->HMACOutputLength);
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 2;
			} else 			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 2;
			} else 			if ( xmldsigSignatureMethodType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 2);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else 			if ( xmldsigSignatureMethodType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 3);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigSignatureMethodType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigSignatureMethodType->ANY.characters, xmldsigSignatureMethodType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 15;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}

/* Complex type name='http://www.w3.org/2000/09/xmldsig#,DigestMethodType',  base type name='anyType',  content type='MIXED',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  particle='((WC[##other:"http://www.w3.org/2000/09/xmldsig#"]){0-UNBOUNDED})',  derivedBy='RESTRICTION'.  */
static int encode_xmldsigDigestMethodType(bitstream_t* stream, struct xmldsigDigestMethodType* xmldsigDigestMethodType) {
	int grammarID = 0;
	int done = 0;
	int wcDone = 0;
	
	
	while(!done) {
		switch(grammarID) {
		case 0:
			/* FirstStartTag[ATTRIBUTE[STRING](Algorithm)] */
			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigDigestMethodType->Algorithm.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigDigestMethodType->Algorithm.characters, xmldsigDigestMethodType->Algorithm.charactersLen);
					}
				}
				grammarID = 1;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 1:
			/* StartTag[START_ELEMENT_GENERIC, END_ELEMENT, CHARACTERS_GENERIC[STRING]] */
			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 2;
			} else 			if ( xmldsigDigestMethodType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else 			if ( xmldsigDigestMethodType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 2);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigDigestMethodType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigDigestMethodType->ANY.characters, xmldsigDigestMethodType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 2;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 2:
			/* Element[START_ELEMENT_GENERIC, END_ELEMENT, CHARACTERS_GENERIC[STRING]] */
			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 2;
			} else 			if ( xmldsigDigestMethodType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else 			if ( xmldsigDigestMethodType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 2);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigDigestMethodType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigDigestMethodType->ANY.characters, xmldsigDigestMethodType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 2;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}

/* Complex type name='http://www.w3.org/2000/09/xmldsig#,RetrievalMethodType',  base type name='anyType',  content type='ELEMENT',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  particle='("http://www.w3.org/2000/09/xmldsig#":Transforms{0-1})',  derivedBy='RESTRICTION'.  */
static int encode_xmldsigRetrievalMethodType(bitstream_t* stream, struct xmldsigRetrievalMethodType* xmldsigRetrievalMethodType) {
	int grammarID = 16;
	int done = 0;
	
	
	while(!done) {
		switch(grammarID) {
		case 16:
			/* FirstStartTag[ATTRIBUTE[STRING](Type), ATTRIBUTE[STRING](URI), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Transforms), END_ELEMENT] */
			if ( xmldsigRetrievalMethodType->Type_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigRetrievalMethodType->Type.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigRetrievalMethodType->Type.characters, xmldsigRetrievalMethodType->Type.charactersLen);
					}
				}
				grammarID = 17;
			} else 			if ( xmldsigRetrievalMethodType->URI_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 1);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigRetrievalMethodType->URI.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigRetrievalMethodType->URI.characters, xmldsigRetrievalMethodType->URI.charactersLen);
					}
				}
				grammarID = 18;
			} else 			if ( xmldsigRetrievalMethodType->Transforms_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 2);
				if(errn == 0) {
					errn = encode_xmldsigTransformsType(stream, &xmldsigRetrievalMethodType->Transforms );
				}
				grammarID = 19;
			} else 			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 3, 3);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 17:
			/* StartTag[ATTRIBUTE[STRING](URI), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Transforms), END_ELEMENT] */
			if ( xmldsigRetrievalMethodType->URI_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigRetrievalMethodType->URI.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigRetrievalMethodType->URI.characters, xmldsigRetrievalMethodType->URI.charactersLen);
					}
				}
				grammarID = 18;
			} else 			if ( xmldsigRetrievalMethodType->Transforms_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					errn = encode_xmldsigTransformsType(stream, &xmldsigRetrievalMethodType->Transforms );
				}
				grammarID = 19;
			} else 			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 2, 2);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 18:
			/* StartTag[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Transforms), END_ELEMENT] */
			if ( xmldsigRetrievalMethodType->Transforms_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					errn = encode_xmldsigTransformsType(stream, &xmldsigRetrievalMethodType->Transforms );
				}
				grammarID = 19;
			} else 			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 19:
			/* Element[END_ELEMENT] */
			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}

/* Complex type name='http://www.w3.org/2000/09/xmldsig#,SignatureValueType',  base type name='base64Binary',  content type='SIMPLE',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  derivedBy='EXTENSION'.  */
static int encode_xmldsigSignatureValueType(bitstream_t* stream, struct xmldsigSignatureValueType* xmldsigSignatureValueType) {
	int grammarID = 20;
	int done = 0;
	
	
	while(!done) {
		switch(grammarID) {
		case 20:
			/* FirstStartTag[ATTRIBUTE[STRING](Id), CHARACTERS[BINARY_BASE64]] */
			if ( xmldsigSignatureValueType->Id_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigSignatureValueType->Id.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigSignatureValueType->Id.characters, xmldsigSignatureValueType->Id.charactersLen);
					}
				}
				grammarID = 21;
			} else 			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigSignatureValueType->CONTENT.bytesLen));
					if (errn == 0) {
						errn = encodeBytes(stream, xmldsigSignatureValueType->CONTENT.bytes, xmldsigSignatureValueType->CONTENT.bytesLen);
					}
				}
				grammarID = 19;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 21:
			/* StartTag[CHARACTERS[BINARY_BASE64]] */
			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigSignatureValueType->CONTENT.bytesLen));
					if (errn == 0) {
						errn = encodeBytes(stream, xmldsigSignatureValueType->CONTENT.bytes, xmldsigSignatureValueType->CONTENT.bytesLen);
					}
				}
				grammarID = 19;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 19:
			/* Element[END_ELEMENT] */
			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}

/* Complex type name='http://www.w3.org/2000/09/xmldsig#,X509IssuerSerialType',  base type name='anyType',  content type='ELEMENT',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  particle='("http://www.w3.org/2000/09/xmldsig#":X509IssuerName,"http://www.w3.org/2000/09/xmldsig#":X509SerialNumber)',  derivedBy='RESTRICTION'.  */
static int encode_xmldsigX509IssuerSerialType(bitstream_t* stream, struct xmldsigX509IssuerSerialType* xmldsigX509IssuerSerialType) {
	int grammarID = 22;
	int done = 0;
	
	
	while(!done) {
		switch(grammarID) {
		case 22:
			/* FirstStartTag[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509IssuerName)] */
			if ( 1 == 1 ) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[STRING]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						/* encode string as string table miss (+2 len)*/
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigX509IssuerSerialType->X509IssuerName.charactersLen + 2));
						if (errn == 0) {
							errn = encodeCharacters(stream, xmldsigX509IssuerSerialType->X509IssuerName.characters, xmldsigX509IssuerSerialType->X509IssuerName.charactersLen);
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 23;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 23:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509SerialNumber)] */
			if ( 1 == 1 ) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[INTEGER]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeInteger64(stream, xmldsigX509IssuerSerialType->X509SerialNumber);
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 19;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 19:
			/* Element[END_ELEMENT] */
			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}

/* Complex type name='http://www.w3.org/2000/09/xmldsig#,SignedInfoType',  base type name='anyType',  content type='ELEMENT',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  particle='("http://www.w3.org/2000/09/xmldsig#":CanonicalizationMethod,"http://www.w3.org/2000/09/xmldsig#":SignatureMethod,"http://www.w3.org/2000/09/xmldsig#":Reference{1-UNBOUNDED})',  derivedBy='RESTRICTION'.  */
static int encode_xmldsigSignedInfoType(bitstream_t* stream, struct xmldsigSignedInfoType* xmldsigSignedInfoType) {
	int grammarID = 24;
	int done = 0;
	
	unsigned int xmldsigSignedInfoType_Reference_currArrayIndex = 0;
	
	while(!done) {
		switch(grammarID) {
		case 24:
			/* FirstStartTag[ATTRIBUTE[STRING](Id), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}CanonicalizationMethod)] */
			if ( xmldsigSignedInfoType->Id_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigSignedInfoType->Id.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigSignedInfoType->Id.characters, xmldsigSignedInfoType->Id.charactersLen);
					}
				}
				grammarID = 25;
			} else 			if ( 1 == 1 ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					errn = encode_xmldsigCanonicalizationMethodType(stream, &xmldsigSignedInfoType->CanonicalizationMethod );
				}
				grammarID = 26;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 25:
			/* StartTag[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}CanonicalizationMethod)] */
			if ( 1 == 1 ) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encode_xmldsigCanonicalizationMethodType(stream, &xmldsigSignedInfoType->CanonicalizationMethod );
				}
				grammarID = 26;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 26:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignatureMethod)] */
			if ( 1 == 1 ) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encode_xmldsigSignatureMethodType(stream, &xmldsigSignedInfoType->SignatureMethod );
				}
				grammarID = 27;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 27:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Reference)] */
			if (xmldsigSignedInfoType_Reference_currArrayIndex < xmldsigSignedInfoType->Reference.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encode_xmldsigReferenceType(stream, &xmldsigSignedInfoType->Reference.array [xmldsigSignedInfoType_Reference_currArrayIndex++]);
				}
				grammarID = 6;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 6:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Reference), END_ELEMENT] */
			if (xmldsigSignedInfoType_Reference_currArrayIndex < xmldsigSignedInfoType->Reference.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					errn = encode_xmldsigReferenceType(stream, &xmldsigSignedInfoType->Reference.array [xmldsigSignedInfoType_Reference_currArrayIndex++]);
				}
				grammarID = 6;
			} else 			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}

/* Complex type name='http://www.w3.org/2000/09/xmldsig#,SignaturePropertiesType',  base type name='anyType',  content type='ELEMENT',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  particle='("http://www.w3.org/2000/09/xmldsig#":SignatureProperty{1-UNBOUNDED})',  derivedBy='RESTRICTION'.  */
static int encode_xmldsigSignaturePropertiesType(bitstream_t* stream, struct xmldsigSignaturePropertiesType* xmldsigSignaturePropertiesType) {
	int grammarID = 28;
	int done = 0;
	
	unsigned int xmldsigSignaturePropertiesType_SignatureProperty_currArrayIndex = 0;
	
	while(!done) {
		switch(grammarID) {
		case 28:
			/* FirstStartTag[ATTRIBUTE[STRING](Id), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignatureProperty)] */
			if ( xmldsigSignaturePropertiesType->Id_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigSignaturePropertiesType->Id.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigSignaturePropertiesType->Id.characters, xmldsigSignaturePropertiesType->Id.charactersLen);
					}
				}
				grammarID = 29;
			} else 			if (xmldsigSignaturePropertiesType_SignatureProperty_currArrayIndex < xmldsigSignaturePropertiesType->SignatureProperty.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					errn = encode_xmldsigSignaturePropertyType(stream, &xmldsigSignaturePropertiesType->SignatureProperty.array [xmldsigSignaturePropertiesType_SignatureProperty_currArrayIndex++]);
				}
				grammarID = 30;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 29:
			/* StartTag[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignatureProperty)] */
			if (xmldsigSignaturePropertiesType_SignatureProperty_currArrayIndex < xmldsigSignaturePropertiesType->SignatureProperty.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encode_xmldsigSignaturePropertyType(stream, &xmldsigSignaturePropertiesType->SignatureProperty.array [xmldsigSignaturePropertiesType_SignatureProperty_currArrayIndex++]);
				}
				grammarID = 30;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 30:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignatureProperty), END_ELEMENT] */
			if (xmldsigSignaturePropertiesType_SignatureProperty_currArrayIndex < xmldsigSignaturePropertiesType->SignatureProperty.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					errn = encode_xmldsigSignaturePropertyType(stream, &xmldsigSignaturePropertiesType->SignatureProperty.array [xmldsigSignaturePropertiesType_SignatureProperty_currArrayIndex++]);
				}
				grammarID = 30;
			} else 			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}

/* Complex type name='http://www.w3.org/2000/09/xmldsig#,SignaturePropertyType',  base type name='anyType',  content type='MIXED',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  particle='((WC[##other:"http://www.w3.org/2000/09/xmldsig#"])){1-UNBOUNDED}',  derivedBy='RESTRICTION'.  */
static int encode_xmldsigSignaturePropertyType(bitstream_t* stream, struct xmldsigSignaturePropertyType* xmldsigSignaturePropertyType) {
	int grammarID = 31;
	int done = 0;
	int wcDone = 0;
	
	
	while(!done) {
		switch(grammarID) {
		case 31:
			/* FirstStartTag[ATTRIBUTE[STRING](Id), ATTRIBUTE[STRING](Target)] */
			if ( xmldsigSignaturePropertyType->Id_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigSignaturePropertyType->Id.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigSignaturePropertyType->Id.characters, xmldsigSignaturePropertyType->Id.charactersLen);
					}
				}
				grammarID = 32;
			} else 			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigSignaturePropertyType->Target.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigSignaturePropertyType->Target.characters, xmldsigSignaturePropertyType->Target.charactersLen);
					}
				}
				grammarID = 33;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 32:
			/* StartTag[ATTRIBUTE[STRING](Target)] */
			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigSignaturePropertyType->Target.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigSignaturePropertyType->Target.characters, xmldsigSignaturePropertyType->Target.charactersLen);
					}
				}
				grammarID = 33;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 33:
			/* StartTag[START_ELEMENT_GENERIC, CHARACTERS_GENERIC[STRING]] */
			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 2;
			} else 			if ( xmldsigSignaturePropertyType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigSignaturePropertyType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigSignaturePropertyType->ANY.characters, xmldsigSignaturePropertyType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 34;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 2:
			/* Element[START_ELEMENT_GENERIC, END_ELEMENT, CHARACTERS_GENERIC[STRING]] */
			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 2;
			} else 			if ( xmldsigSignaturePropertyType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else 			if ( xmldsigSignaturePropertyType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 2);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigSignaturePropertyType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigSignaturePropertyType->ANY.characters, xmldsigSignaturePropertyType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 2;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 34:
			/* Element[START_ELEMENT_GENERIC, CHARACTERS_GENERIC[STRING]] */
			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 2;
			} else 			if ( xmldsigSignaturePropertyType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigSignaturePropertyType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigSignaturePropertyType->ANY.characters, xmldsigSignaturePropertyType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 34;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}

/* Complex type name='http://www.w3.org/2000/09/xmldsig#,KeyValueType',  base type name='anyType',  content type='MIXED',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  particle='("http://www.w3.org/2000/09/xmldsig#":DSAKeyValue|"http://www.w3.org/2000/09/xmldsig#":RSAKeyValue|(WC[##other:"http://www.w3.org/2000/09/xmldsig#"]))',  derivedBy='RESTRICTION'.  */
static int encode_xmldsigKeyValueType(bitstream_t* stream, struct xmldsigKeyValueType* xmldsigKeyValueType) {
	int grammarID = 35;
	int done = 0;
	int wcDone = 0;
	
	
	while(!done) {
		switch(grammarID) {
		case 35:
			/* FirstStartTag[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}DSAKeyValue), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}RSAKeyValue), START_ELEMENT_GENERIC, CHARACTERS_GENERIC[STRING]] */
			if ( xmldsigKeyValueType->DSAKeyValue_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 0);
				if(errn == 0) {
					errn = encode_xmldsigDSAKeyValueType(stream, &xmldsigKeyValueType->DSAKeyValue );
				}
				grammarID = 36;
			} else 			if ( xmldsigKeyValueType->RSAKeyValue_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 1);
				if(errn == 0) {
					errn = encode_xmldsigRSAKeyValueType(stream, &xmldsigKeyValueType->RSAKeyValue );
				}
				grammarID = 36;
			} else 			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 36;
			} else 			if ( xmldsigKeyValueType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 3);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigKeyValueType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigKeyValueType->ANY.characters, xmldsigKeyValueType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 37;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 36:
			/* Element[END_ELEMENT, CHARACTERS_GENERIC[STRING]] */
			if ( xmldsigKeyValueType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else 			if ( xmldsigKeyValueType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigKeyValueType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigKeyValueType->ANY.characters, xmldsigKeyValueType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 36;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 37:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}DSAKeyValue), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}RSAKeyValue), START_ELEMENT_GENERIC, CHARACTERS_GENERIC[STRING]] */
			if ( xmldsigKeyValueType->DSAKeyValue_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 0);
				if(errn == 0) {
					errn = encode_xmldsigDSAKeyValueType(stream, &xmldsigKeyValueType->DSAKeyValue );
				}
				grammarID = 36;
			} else 			if ( xmldsigKeyValueType->RSAKeyValue_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 1);
				if(errn == 0) {
					errn = encode_xmldsigRSAKeyValueType(stream, &xmldsigKeyValueType->RSAKeyValue );
				}
				grammarID = 36;
			} else 			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 36;
			} else 			if ( xmldsigKeyValueType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 3);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigKeyValueType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigKeyValueType->ANY.characters, xmldsigKeyValueType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 37;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}

/* Complex type name='http://www.w3.org/2000/09/xmldsig#,RSAKeyValueType',  base type name='anyType',  content type='ELEMENT',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  particle='("http://www.w3.org/2000/09/xmldsig#":Modulus,"http://www.w3.org/2000/09/xmldsig#":Exponent)',  derivedBy='RESTRICTION'.  */
static int encode_xmldsigRSAKeyValueType(bitstream_t* stream, struct xmldsigRSAKeyValueType* xmldsigRSAKeyValueType) {
	int grammarID = 38;
	int done = 0;
	
	
	while(!done) {
		switch(grammarID) {
		case 38:
			/* FirstStartTag[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Modulus)] */
			if ( 1 == 1 ) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigRSAKeyValueType->Modulus.bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigRSAKeyValueType->Modulus.bytes, xmldsigRSAKeyValueType->Modulus.bytesLen);
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 39;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 39:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Exponent)] */
			if ( 1 == 1 ) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigRSAKeyValueType->Exponent.bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigRSAKeyValueType->Exponent.bytes, xmldsigRSAKeyValueType->Exponent.bytesLen);
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 19;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 19:
			/* Element[END_ELEMENT] */
			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}

/* Complex type name='http://www.w3.org/2000/09/xmldsig#,PGPDataType',  base type name='anyType',  content type='ELEMENT',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  particle='(("http://www.w3.org/2000/09/xmldsig#":PGPKeyID,"http://www.w3.org/2000/09/xmldsig#":PGPKeyPacket{0-1},(WC[##other:"http://www.w3.org/2000/09/xmldsig#"]){0-UNBOUNDED})|("http://www.w3.org/2000/09/xmldsig#":PGPKeyPacket,(WC[##other:"http://www.w3.org/2000/09/xmldsig#"]){0-UNBOUNDED}))',  derivedBy='RESTRICTION'.  */
static int encode_xmldsigPGPDataType(bitstream_t* stream, struct xmldsigPGPDataType* xmldsigPGPDataType) {
	int grammarID = 40;
	int done = 0;
	int wcDone = 0;
	
	
	while(!done) {
		switch(grammarID) {
		case 40:
			/* FirstStartTag[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}PGPKeyID), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}PGPKeyPacket)] */
			if ( xmldsigPGPDataType->PGPKeyID_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigPGPDataType->PGPKeyID.bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigPGPDataType->PGPKeyID.bytes, xmldsigPGPDataType->PGPKeyID.bytesLen);
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 41;
			} else 			if ( xmldsigPGPDataType->PGPKeyPacket_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigPGPDataType->PGPKeyPacket.bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigPGPDataType->PGPKeyPacket.bytes, xmldsigPGPDataType->PGPKeyPacket.bytesLen);
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 42;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 41:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}PGPKeyPacket), START_ELEMENT_GENERIC, END_ELEMENT] */
			if ( xmldsigPGPDataType->PGPKeyPacket_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigPGPDataType->PGPKeyPacket.bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigPGPDataType->PGPKeyPacket.bytes, xmldsigPGPDataType->PGPKeyPacket.bytesLen);
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 42;
			} else 			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 42;
			} else 			if ( xmldsigPGPDataType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 2);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 42:
			/* Element[START_ELEMENT_GENERIC, END_ELEMENT] */
			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 42;
			} else 			if ( xmldsigPGPDataType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}

/* Complex type name='http://www.w3.org/2000/09/xmldsig#,TransformsType',  base type name='anyType',  content type='ELEMENT',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  particle='("http://www.w3.org/2000/09/xmldsig#":Transform{1-UNBOUNDED})',  derivedBy='RESTRICTION'.  */
static int encode_xmldsigTransformsType(bitstream_t* stream, struct xmldsigTransformsType* xmldsigTransformsType) {
	int grammarID = 43;
	int done = 0;
	
	unsigned int xmldsigTransformsType_Transform_currArrayIndex = 0;
	
	while(!done) {
		switch(grammarID) {
		case 43:
			/* FirstStartTag[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Transform)] */
			if (xmldsigTransformsType_Transform_currArrayIndex < xmldsigTransformsType->Transform.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encode_xmldsigTransformType(stream, &xmldsigTransformsType->Transform.array [xmldsigTransformsType_Transform_currArrayIndex++]);
				}
				grammarID = 44;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 44:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Transform), END_ELEMENT] */
			if (xmldsigTransformsType_Transform_currArrayIndex < xmldsigTransformsType->Transform.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					errn = encode_xmldsigTransformType(stream, &xmldsigTransformsType->Transform.array [xmldsigTransformsType_Transform_currArrayIndex++]);
				}
				grammarID = 44;
			} else 			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}

/* Complex type name='http://www.w3.org/2000/09/xmldsig#,X509DataType',  base type name='anyType',  content type='ELEMENT',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  particle='(("http://www.w3.org/2000/09/xmldsig#":X509IssuerSerial|"http://www.w3.org/2000/09/xmldsig#":X509SKI|"http://www.w3.org/2000/09/xmldsig#":X509SubjectName|"http://www.w3.org/2000/09/xmldsig#":X509Certificate|"http://www.w3.org/2000/09/xmldsig#":X509CRL|(WC[##other:"http://www.w3.org/2000/09/xmldsig#"]))){1-UNBOUNDED}',  derivedBy='RESTRICTION'.  */
static int encode_xmldsigX509DataType(bitstream_t* stream, struct xmldsigX509DataType* xmldsigX509DataType) {
	int grammarID = 45;
	int done = 0;
	int wcDone = 0;
	
	unsigned int xmldsigX509DataType_X509IssuerSerial_currArrayIndex = 0;
	unsigned int xmldsigX509DataType_X509SKI_currArrayIndex = 0;
	unsigned int xmldsigX509DataType_X509SubjectName_currArrayIndex = 0;
	unsigned int xmldsigX509DataType_X509Certificate_currArrayIndex = 0;
	unsigned int xmldsigX509DataType_X509CRL_currArrayIndex = 0;
	
	while(!done) {
		switch(grammarID) {
		case 45:
			/* FirstStartTag[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509IssuerSerial), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509SKI), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509SubjectName), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509Certificate), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509CRL), START_ELEMENT_GENERIC] */
			if (xmldsigX509DataType_X509IssuerSerial_currArrayIndex < xmldsigX509DataType->X509IssuerSerial.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 0);
				if(errn == 0) {
					errn = encode_xmldsigX509IssuerSerialType(stream, &xmldsigX509DataType->X509IssuerSerial.array [xmldsigX509DataType_X509IssuerSerial_currArrayIndex++]);
				}
				grammarID = 46;
			} else 			if (xmldsigX509DataType_X509SKI_currArrayIndex < xmldsigX509DataType->X509SKI.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 1);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigX509DataType->X509SKI.array[xmldsigX509DataType_X509SKI_currArrayIndex].bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigX509DataType->X509SKI.array[xmldsigX509DataType_X509SKI_currArrayIndex].bytes, xmldsigX509DataType->X509SKI.array[xmldsigX509DataType_X509SKI_currArrayIndex].bytesLen);
							xmldsigX509DataType_X509SKI_currArrayIndex++;
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 46;
			} else 			if (xmldsigX509DataType_X509SubjectName_currArrayIndex < xmldsigX509DataType->X509SubjectName.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 2);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[STRING]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						/* encode string as string table miss (+2 len)*/
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigX509DataType->X509SubjectName.array[xmldsigX509DataType_X509SubjectName_currArrayIndex].charactersLen + 2));
						if (errn == 0) {
							errn = encodeCharacters(stream, xmldsigX509DataType->X509SubjectName.array[xmldsigX509DataType_X509SubjectName_currArrayIndex].characters, xmldsigX509DataType->X509SubjectName.array[xmldsigX509DataType_X509SubjectName_currArrayIndex].charactersLen);
							xmldsigX509DataType_X509SubjectName_currArrayIndex++;
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 46;
			} else 			if (xmldsigX509DataType_X509Certificate_currArrayIndex < xmldsigX509DataType->X509Certificate.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 3);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigX509DataType->X509Certificate.array[xmldsigX509DataType_X509Certificate_currArrayIndex].bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigX509DataType->X509Certificate.array[xmldsigX509DataType_X509Certificate_currArrayIndex].bytes, xmldsigX509DataType->X509Certificate.array[xmldsigX509DataType_X509Certificate_currArrayIndex].bytesLen);
							xmldsigX509DataType_X509Certificate_currArrayIndex++;
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 46;
			} else 			if (xmldsigX509DataType_X509CRL_currArrayIndex < xmldsigX509DataType->X509CRL.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 4);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigX509DataType->X509CRL.array[xmldsigX509DataType_X509CRL_currArrayIndex].bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigX509DataType->X509CRL.array[xmldsigX509DataType_X509CRL_currArrayIndex].bytes, xmldsigX509DataType->X509CRL.array[xmldsigX509DataType_X509CRL_currArrayIndex].bytesLen);
							xmldsigX509DataType_X509CRL_currArrayIndex++;
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 46;
			} else 			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 46;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 46:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509IssuerSerial), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509SKI), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509SubjectName), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509Certificate), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509CRL), START_ELEMENT_GENERIC, END_ELEMENT] */
			if (xmldsigX509DataType_X509IssuerSerial_currArrayIndex < xmldsigX509DataType->X509IssuerSerial.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 0);
				if(errn == 0) {
					errn = encode_xmldsigX509IssuerSerialType(stream, &xmldsigX509DataType->X509IssuerSerial.array [xmldsigX509DataType_X509IssuerSerial_currArrayIndex++]);
				}
				grammarID = 46;
			} else 			if (xmldsigX509DataType_X509SKI_currArrayIndex < xmldsigX509DataType->X509SKI.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 1);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigX509DataType->X509SKI.array[xmldsigX509DataType_X509SKI_currArrayIndex].bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigX509DataType->X509SKI.array[xmldsigX509DataType_X509SKI_currArrayIndex].bytes, xmldsigX509DataType->X509SKI.array[xmldsigX509DataType_X509SKI_currArrayIndex].bytesLen);
							xmldsigX509DataType_X509SKI_currArrayIndex++;
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 46;
			} else 			if (xmldsigX509DataType_X509SubjectName_currArrayIndex < xmldsigX509DataType->X509SubjectName.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 2);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[STRING]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						/* encode string as string table miss (+2 len)*/
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigX509DataType->X509SubjectName.array[xmldsigX509DataType_X509SubjectName_currArrayIndex].charactersLen + 2));
						if (errn == 0) {
							errn = encodeCharacters(stream, xmldsigX509DataType->X509SubjectName.array[xmldsigX509DataType_X509SubjectName_currArrayIndex].characters, xmldsigX509DataType->X509SubjectName.array[xmldsigX509DataType_X509SubjectName_currArrayIndex].charactersLen);
							xmldsigX509DataType_X509SubjectName_currArrayIndex++;
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 46;
			} else 			if (xmldsigX509DataType_X509Certificate_currArrayIndex < xmldsigX509DataType->X509Certificate.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 3);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigX509DataType->X509Certificate.array[xmldsigX509DataType_X509Certificate_currArrayIndex].bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigX509DataType->X509Certificate.array[xmldsigX509DataType_X509Certificate_currArrayIndex].bytes, xmldsigX509DataType->X509Certificate.array[xmldsigX509DataType_X509Certificate_currArrayIndex].bytesLen);
							xmldsigX509DataType_X509Certificate_currArrayIndex++;
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 46;
			} else 			if (xmldsigX509DataType_X509CRL_currArrayIndex < xmldsigX509DataType->X509CRL.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 4);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigX509DataType->X509CRL.array[xmldsigX509DataType_X509CRL_currArrayIndex].bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigX509DataType->X509CRL.array[xmldsigX509DataType_X509CRL_currArrayIndex].bytes, xmldsigX509DataType->X509CRL.array[xmldsigX509DataType_X509CRL_currArrayIndex].bytesLen);
							xmldsigX509DataType_X509CRL_currArrayIndex++;
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 46;
			} else 			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 46;
			} else 			if ( xmldsigX509DataType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 6);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}

/* Complex type name='http://www.w3.org/2000/09/xmldsig#,SignatureType',  base type name='anyType',  content type='ELEMENT',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  particle='("http://www.w3.org/2000/09/xmldsig#":SignedInfo,"http://www.w3.org/2000/09/xmldsig#":SignatureValue,"http://www.w3.org/2000/09/xmldsig#":KeyInfo{0-1},"http://www.w3.org/2000/09/xmldsig#":Object{0-UNBOUNDED})',  derivedBy='RESTRICTION'.  */
static int encode_xmldsigSignatureType(bitstream_t* stream, struct xmldsigSignatureType* xmldsigSignatureType) {
	int grammarID = 47;
	int done = 0;
	
	unsigned int xmldsigSignatureType_Object_currArrayIndex = 0;
	
	while(!done) {
		switch(grammarID) {
		case 47:
			/* FirstStartTag[ATTRIBUTE[STRING](Id), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignedInfo)] */
			if ( xmldsigSignatureType->Id_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigSignatureType->Id.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigSignatureType->Id.characters, xmldsigSignatureType->Id.charactersLen);
					}
				}
				grammarID = 48;
			} else 			if ( 1 == 1 ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					errn = encode_xmldsigSignedInfoType(stream, &xmldsigSignatureType->SignedInfo );
				}
				grammarID = 49;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 48:
			/* StartTag[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignedInfo)] */
			if ( 1 == 1 ) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encode_xmldsigSignedInfoType(stream, &xmldsigSignatureType->SignedInfo );
				}
				grammarID = 49;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 49:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignatureValue)] */
			if ( 1 == 1 ) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encode_xmldsigSignatureValueType(stream, &xmldsigSignatureType->SignatureValue );
				}
				grammarID = 50;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 50:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}KeyInfo), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Object), END_ELEMENT] */
			if ( xmldsigSignatureType->KeyInfo_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					errn = encode_xmldsigKeyInfoType(stream, &xmldsigSignatureType->KeyInfo );
				}
				grammarID = 51;
			} else 			if (xmldsigSignatureType_Object_currArrayIndex < xmldsigSignatureType->Object.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					errn = encode_xmldsigObjectType(stream, &xmldsigSignatureType->Object.array [xmldsigSignatureType_Object_currArrayIndex++]);
				}
				grammarID = 51;
			} else 			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 2, 2);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 51:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Object), END_ELEMENT] */
			if (xmldsigSignatureType_Object_currArrayIndex < xmldsigSignatureType->Object.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					errn = encode_xmldsigObjectType(stream, &xmldsigSignatureType->Object.array [xmldsigSignatureType_Object_currArrayIndex++]);
				}
				grammarID = 51;
			} else 			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}

/* Complex type name='http://www.w3.org/2000/09/xmldsig#,DSAKeyValueType',  base type name='anyType',  content type='ELEMENT',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  particle='(("http://www.w3.org/2000/09/xmldsig#":P,"http://www.w3.org/2000/09/xmldsig#":Q){0-1},"http://www.w3.org/2000/09/xmldsig#":G{0-1},"http://www.w3.org/2000/09/xmldsig#":Y,"http://www.w3.org/2000/09/xmldsig#":J{0-1},("http://www.w3.org/2000/09/xmldsig#":Seed,"http://www.w3.org/2000/09/xmldsig#":PgenCounter){0-1})',  derivedBy='RESTRICTION'.  */
static int encode_xmldsigDSAKeyValueType(bitstream_t* stream, struct xmldsigDSAKeyValueType* xmldsigDSAKeyValueType) {
	int grammarID = 52;
	int done = 0;
	
	
	while(!done) {
		switch(grammarID) {
		case 52:
			/* FirstStartTag[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}P), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}G), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Y)] */
			if ( xmldsigDSAKeyValueType->P_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigDSAKeyValueType->P.bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigDSAKeyValueType->P.bytes, xmldsigDSAKeyValueType->P.bytesLen);
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 53;
			} else 			if ( xmldsigDSAKeyValueType->G_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigDSAKeyValueType->G.bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigDSAKeyValueType->G.bytes, xmldsigDSAKeyValueType->G.bytesLen);
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 54;
			} else 			if ( 1 == 1 ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 2);
				if(errn == 0) {
					/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigDSAKeyValueType->Y.bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigDSAKeyValueType->Y.bytes, xmldsigDSAKeyValueType->Y.bytesLen);
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 55;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 53:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Q)] */
			if ( xmldsigDSAKeyValueType->Q_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigDSAKeyValueType->Q.bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigDSAKeyValueType->Q.bytes, xmldsigDSAKeyValueType->Q.bytesLen);
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 56;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 56:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}G), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Y)] */
			if ( xmldsigDSAKeyValueType->G_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigDSAKeyValueType->G.bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigDSAKeyValueType->G.bytes, xmldsigDSAKeyValueType->G.bytesLen);
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 54;
			} else 			if ( 1 == 1 ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigDSAKeyValueType->Y.bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigDSAKeyValueType->Y.bytes, xmldsigDSAKeyValueType->Y.bytesLen);
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 55;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 54:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Y)] */
			if ( 1 == 1 ) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigDSAKeyValueType->Y.bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigDSAKeyValueType->Y.bytes, xmldsigDSAKeyValueType->Y.bytesLen);
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 55;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 55:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}J), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Seed), END_ELEMENT] */
			if ( xmldsigDSAKeyValueType->J_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigDSAKeyValueType->J.bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigDSAKeyValueType->J.bytes, xmldsigDSAKeyValueType->J.bytesLen);
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 57;
			} else 			if ( xmldsigDSAKeyValueType->Seed_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigDSAKeyValueType->Seed.bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigDSAKeyValueType->Seed.bytes, xmldsigDSAKeyValueType->Seed.bytesLen);
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 58;
			} else 			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 2, 2);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 57:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Seed), END_ELEMENT] */
			if ( xmldsigDSAKeyValueType->Seed_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigDSAKeyValueType->Seed.bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigDSAKeyValueType->Seed.bytes, xmldsigDSAKeyValueType->Seed.bytesLen);
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 58;
			} else 			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 58:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}PgenCounter)] */
			if ( xmldsigDSAKeyValueType->PgenCounter_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigDSAKeyValueType->PgenCounter.bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigDSAKeyValueType->PgenCounter.bytes, xmldsigDSAKeyValueType->PgenCounter.bytesLen);
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 19;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 19:
			/* Element[END_ELEMENT] */
			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}

/* Complex type name='http://www.w3.org/2000/09/xmldsig#,ReferenceType',  base type name='anyType',  content type='ELEMENT',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  particle='("http://www.w3.org/2000/09/xmldsig#":Transforms{0-1},"http://www.w3.org/2000/09/xmldsig#":DigestMethod,"http://www.w3.org/2000/09/xmldsig#":DigestValue)',  derivedBy='RESTRICTION'.  */
static int encode_xmldsigReferenceType(bitstream_t* stream, struct xmldsigReferenceType* xmldsigReferenceType) {
	int grammarID = 59;
	int done = 0;
	
	
	while(!done) {
		switch(grammarID) {
		case 59:
			/* FirstStartTag[ATTRIBUTE[STRING](Id), ATTRIBUTE[STRING](Type), ATTRIBUTE[STRING](URI), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Transforms), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}DigestMethod)] */
			if ( xmldsigReferenceType->Id_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigReferenceType->Id.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigReferenceType->Id.characters, xmldsigReferenceType->Id.charactersLen);
					}
				}
				grammarID = 60;
			} else 			if ( xmldsigReferenceType->Type_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 1);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigReferenceType->Type.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigReferenceType->Type.characters, xmldsigReferenceType->Type.charactersLen);
					}
				}
				grammarID = 61;
			} else 			if ( xmldsigReferenceType->URI_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 2);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigReferenceType->URI.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigReferenceType->URI.characters, xmldsigReferenceType->URI.charactersLen);
					}
				}
				grammarID = 62;
			} else 			if ( xmldsigReferenceType->Transforms_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 3);
				if(errn == 0) {
					errn = encode_xmldsigTransformsType(stream, &xmldsigReferenceType->Transforms );
				}
				grammarID = 63;
			} else 			if ( 1 == 1 ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 4);
				if(errn == 0) {
					errn = encode_xmldsigDigestMethodType(stream, &xmldsigReferenceType->DigestMethod );
				}
				grammarID = 64;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 60:
			/* StartTag[ATTRIBUTE[STRING](Type), ATTRIBUTE[STRING](URI), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Transforms), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}DigestMethod)] */
			if ( xmldsigReferenceType->Type_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigReferenceType->Type.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigReferenceType->Type.characters, xmldsigReferenceType->Type.charactersLen);
					}
				}
				grammarID = 61;
			} else 			if ( xmldsigReferenceType->URI_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 1);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigReferenceType->URI.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigReferenceType->URI.characters, xmldsigReferenceType->URI.charactersLen);
					}
				}
				grammarID = 62;
			} else 			if ( xmldsigReferenceType->Transforms_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 2);
				if(errn == 0) {
					errn = encode_xmldsigTransformsType(stream, &xmldsigReferenceType->Transforms );
				}
				grammarID = 63;
			} else 			if ( 1 == 1 ) {
				errn = encodeNBitUnsignedInteger(stream, 3, 3);
				if(errn == 0) {
					errn = encode_xmldsigDigestMethodType(stream, &xmldsigReferenceType->DigestMethod );
				}
				grammarID = 64;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 61:
			/* StartTag[ATTRIBUTE[STRING](URI), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Transforms), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}DigestMethod)] */
			if ( xmldsigReferenceType->URI_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigReferenceType->URI.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigReferenceType->URI.characters, xmldsigReferenceType->URI.charactersLen);
					}
				}
				grammarID = 62;
			} else 			if ( xmldsigReferenceType->Transforms_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					errn = encode_xmldsigTransformsType(stream, &xmldsigReferenceType->Transforms );
				}
				grammarID = 63;
			} else 			if ( 1 == 1 ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 2);
				if(errn == 0) {
					errn = encode_xmldsigDigestMethodType(stream, &xmldsigReferenceType->DigestMethod );
				}
				grammarID = 64;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 62:
			/* StartTag[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Transforms), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}DigestMethod)] */
			if ( xmldsigReferenceType->Transforms_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					errn = encode_xmldsigTransformsType(stream, &xmldsigReferenceType->Transforms );
				}
				grammarID = 63;
			} else 			if ( 1 == 1 ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					errn = encode_xmldsigDigestMethodType(stream, &xmldsigReferenceType->DigestMethod );
				}
				grammarID = 64;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 63:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}DigestMethod)] */
			if ( 1 == 1 ) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encode_xmldsigDigestMethodType(stream, &xmldsigReferenceType->DigestMethod );
				}
				grammarID = 64;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 64:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}DigestValue)] */
			if ( 1 == 1 ) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigReferenceType->DigestValue.bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigReferenceType->DigestValue.bytes, xmldsigReferenceType->DigestValue.bytesLen);
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 19;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 19:
			/* Element[END_ELEMENT] */
			if (1==1) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}

/* Complex type name='http://www.w3.org/2000/09/xmldsig#,SPKIDataType',  base type name='anyType',  content type='ELEMENT',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  particle='("http://www.w3.org/2000/09/xmldsig#":SPKISexp,(WC[##other:"http://www.w3.org/2000/09/xmldsig#"]){0-1}){1-UNBOUNDED}',  derivedBy='RESTRICTION'.  */
static int encode_xmldsigSPKIDataType(bitstream_t* stream, struct xmldsigSPKIDataType* xmldsigSPKIDataType) {
	int grammarID = 65;
	int done = 0;
	int wcDone = 0;
	
	unsigned int xmldsigSPKIDataType_SPKISexp_currArrayIndex = 0;
	
	while(!done) {
		switch(grammarID) {
		case 65:
			/* FirstStartTag[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SPKISexp)] */
			if (xmldsigSPKIDataType_SPKISexp_currArrayIndex < xmldsigSPKIDataType->SPKISexp.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigSPKIDataType->SPKISexp.array[xmldsigSPKIDataType_SPKISexp_currArrayIndex].bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigSPKIDataType->SPKISexp.array[xmldsigSPKIDataType_SPKISexp_currArrayIndex].bytes, xmldsigSPKIDataType->SPKISexp.array[xmldsigSPKIDataType_SPKISexp_currArrayIndex].bytesLen);
							xmldsigSPKIDataType_SPKISexp_currArrayIndex++;
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 66;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 66:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SPKISexp), START_ELEMENT_GENERIC, END_ELEMENT] */
			if (xmldsigSPKIDataType_SPKISexp_currArrayIndex < xmldsigSPKIDataType->SPKISexp.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigSPKIDataType->SPKISexp.array[xmldsigSPKIDataType_SPKISexp_currArrayIndex].bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigSPKIDataType->SPKISexp.array[xmldsigSPKIDataType_SPKISexp_currArrayIndex].bytes, xmldsigSPKIDataType->SPKISexp.array[xmldsigSPKIDataType_SPKISexp_currArrayIndex].bytesLen);
							xmldsigSPKIDataType_SPKISexp_currArrayIndex++;
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 66;
			} else 			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 67;
			} else 			if ( xmldsigSPKIDataType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 2);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 67:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SPKISexp), END_ELEMENT] */
			if (xmldsigSPKIDataType_SPKISexp_currArrayIndex < xmldsigSPKIDataType->SPKISexp.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 0);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[BINARY_BASE64]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigSPKIDataType->SPKISexp.array[xmldsigSPKIDataType_SPKISexp_currArrayIndex].bytesLen));
						if (errn == 0) {
							errn = encodeBytes(stream, xmldsigSPKIDataType->SPKISexp.array[xmldsigSPKIDataType_SPKISexp_currArrayIndex].bytes, xmldsigSPKIDataType->SPKISexp.array[xmldsigSPKIDataType_SPKISexp_currArrayIndex].bytesLen);
							xmldsigSPKIDataType_SPKISexp_currArrayIndex++;
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 66;
			} else 			if ( xmldsigSPKIDataType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 2, 1);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}

/* Complex type name='http://www.w3.org/2000/09/xmldsig#,KeyInfoType',  base type name='anyType',  content type='MIXED',  isAbstract='false',  hasTypeId='false',  final='0',  block='0',  particle='("http://www.w3.org/2000/09/xmldsig#":KeyName|"http://www.w3.org/2000/09/xmldsig#":KeyValue|"http://www.w3.org/2000/09/xmldsig#":RetrievalMethod|"http://www.w3.org/2000/09/xmldsig#":X509Data|"http://www.w3.org/2000/09/xmldsig#":PGPData|"http://www.w3.org/2000/09/xmldsig#":SPKIData|"http://www.w3.org/2000/09/xmldsig#":MgmtData|(WC[##other:"http://www.w3.org/2000/09/xmldsig#"])){1-UNBOUNDED}',  derivedBy='RESTRICTION'.  */
static int encode_xmldsigKeyInfoType(bitstream_t* stream, struct xmldsigKeyInfoType* xmldsigKeyInfoType) {
	int grammarID = 68;
	int done = 0;
	int wcDone = 0;
	
	unsigned int xmldsigKeyInfoType_KeyName_currArrayIndex = 0;
	unsigned int xmldsigKeyInfoType_KeyValue_currArrayIndex = 0;
	unsigned int xmldsigKeyInfoType_RetrievalMethod_currArrayIndex = 0;
	unsigned int xmldsigKeyInfoType_X509Data_currArrayIndex = 0;
	unsigned int xmldsigKeyInfoType_PGPData_currArrayIndex = 0;
	unsigned int xmldsigKeyInfoType_SPKIData_currArrayIndex = 0;
	unsigned int xmldsigKeyInfoType_MgmtData_currArrayIndex = 0;
	
	while(!done) {
		switch(grammarID) {
		case 68:
			/* FirstStartTag[ATTRIBUTE[STRING](Id), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}KeyName), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}KeyValue), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}RetrievalMethod), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509Data), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}PGPData), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SPKIData), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}MgmtData), START_ELEMENT_GENERIC, CHARACTERS_GENERIC[STRING]] */
			if ( xmldsigKeyInfoType->Id_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigKeyInfoType->Id.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigKeyInfoType->Id.characters, xmldsigKeyInfoType->Id.charactersLen);
					}
				}
				grammarID = 69;
			} else 			if (xmldsigKeyInfoType_KeyName_currArrayIndex < xmldsigKeyInfoType->KeyName.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 1);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[STRING]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						/* encode string as string table miss (+2 len)*/
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigKeyInfoType->KeyName.array[xmldsigKeyInfoType_KeyName_currArrayIndex].charactersLen + 2));
						if (errn == 0) {
							errn = encodeCharacters(stream, xmldsigKeyInfoType->KeyName.array[xmldsigKeyInfoType_KeyName_currArrayIndex].characters, xmldsigKeyInfoType->KeyName.array[xmldsigKeyInfoType_KeyName_currArrayIndex].charactersLen);
							xmldsigKeyInfoType_KeyName_currArrayIndex++;
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_KeyValue_currArrayIndex < xmldsigKeyInfoType->KeyValue.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 2);
				if(errn == 0) {
					errn = encode_xmldsigKeyValueType(stream, &xmldsigKeyInfoType->KeyValue.array [xmldsigKeyInfoType_KeyValue_currArrayIndex++]);
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_RetrievalMethod_currArrayIndex < xmldsigKeyInfoType->RetrievalMethod.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 3);
				if(errn == 0) {
					errn = encode_xmldsigRetrievalMethodType(stream, &xmldsigKeyInfoType->RetrievalMethod.array [xmldsigKeyInfoType_RetrievalMethod_currArrayIndex++]);
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_X509Data_currArrayIndex < xmldsigKeyInfoType->X509Data.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 4);
				if(errn == 0) {
					errn = encode_xmldsigX509DataType(stream, &xmldsigKeyInfoType->X509Data.array [xmldsigKeyInfoType_X509Data_currArrayIndex++]);
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_PGPData_currArrayIndex < xmldsigKeyInfoType->PGPData.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 5);
				if(errn == 0) {
					errn = encode_xmldsigPGPDataType(stream, &xmldsigKeyInfoType->PGPData.array [xmldsigKeyInfoType_PGPData_currArrayIndex++]);
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_SPKIData_currArrayIndex < xmldsigKeyInfoType->SPKIData.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 6);
				if(errn == 0) {
					errn = encode_xmldsigSPKIDataType(stream, &xmldsigKeyInfoType->SPKIData.array [xmldsigKeyInfoType_SPKIData_currArrayIndex++]);
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_MgmtData_currArrayIndex < xmldsigKeyInfoType->MgmtData.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 7);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[STRING]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						/* encode string as string table miss (+2 len)*/
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigKeyInfoType->MgmtData.array[xmldsigKeyInfoType_MgmtData_currArrayIndex].charactersLen + 2));
						if (errn == 0) {
							errn = encodeCharacters(stream, xmldsigKeyInfoType->MgmtData.array[xmldsigKeyInfoType_MgmtData_currArrayIndex].characters, xmldsigKeyInfoType->MgmtData.array[xmldsigKeyInfoType_MgmtData_currArrayIndex].charactersLen);
							xmldsigKeyInfoType_MgmtData_currArrayIndex++;
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 70;
			} else 			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 70;
			} else 			if ( xmldsigKeyInfoType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 9);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigKeyInfoType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigKeyInfoType->ANY.characters, xmldsigKeyInfoType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 71;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 69:
			/* StartTag[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}KeyName), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}KeyValue), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}RetrievalMethod), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509Data), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}PGPData), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SPKIData), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}MgmtData), START_ELEMENT_GENERIC, CHARACTERS_GENERIC[STRING]] */
			if (xmldsigKeyInfoType_KeyName_currArrayIndex < xmldsigKeyInfoType->KeyName.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 0);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[STRING]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						/* encode string as string table miss (+2 len)*/
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigKeyInfoType->KeyName.array[xmldsigKeyInfoType_KeyName_currArrayIndex].charactersLen + 2));
						if (errn == 0) {
							errn = encodeCharacters(stream, xmldsigKeyInfoType->KeyName.array[xmldsigKeyInfoType_KeyName_currArrayIndex].characters, xmldsigKeyInfoType->KeyName.array[xmldsigKeyInfoType_KeyName_currArrayIndex].charactersLen);
							xmldsigKeyInfoType_KeyName_currArrayIndex++;
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_KeyValue_currArrayIndex < xmldsigKeyInfoType->KeyValue.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 1);
				if(errn == 0) {
					errn = encode_xmldsigKeyValueType(stream, &xmldsigKeyInfoType->KeyValue.array [xmldsigKeyInfoType_KeyValue_currArrayIndex++]);
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_RetrievalMethod_currArrayIndex < xmldsigKeyInfoType->RetrievalMethod.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 2);
				if(errn == 0) {
					errn = encode_xmldsigRetrievalMethodType(stream, &xmldsigKeyInfoType->RetrievalMethod.array [xmldsigKeyInfoType_RetrievalMethod_currArrayIndex++]);
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_X509Data_currArrayIndex < xmldsigKeyInfoType->X509Data.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 3);
				if(errn == 0) {
					errn = encode_xmldsigX509DataType(stream, &xmldsigKeyInfoType->X509Data.array [xmldsigKeyInfoType_X509Data_currArrayIndex++]);
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_PGPData_currArrayIndex < xmldsigKeyInfoType->PGPData.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 4);
				if(errn == 0) {
					errn = encode_xmldsigPGPDataType(stream, &xmldsigKeyInfoType->PGPData.array [xmldsigKeyInfoType_PGPData_currArrayIndex++]);
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_SPKIData_currArrayIndex < xmldsigKeyInfoType->SPKIData.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 5);
				if(errn == 0) {
					errn = encode_xmldsigSPKIDataType(stream, &xmldsigKeyInfoType->SPKIData.array [xmldsigKeyInfoType_SPKIData_currArrayIndex++]);
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_MgmtData_currArrayIndex < xmldsigKeyInfoType->MgmtData.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 6);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[STRING]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						/* encode string as string table miss (+2 len)*/
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigKeyInfoType->MgmtData.array[xmldsigKeyInfoType_MgmtData_currArrayIndex].charactersLen + 2));
						if (errn == 0) {
							errn = encodeCharacters(stream, xmldsigKeyInfoType->MgmtData.array[xmldsigKeyInfoType_MgmtData_currArrayIndex].characters, xmldsigKeyInfoType->MgmtData.array[xmldsigKeyInfoType_MgmtData_currArrayIndex].charactersLen);
							xmldsigKeyInfoType_MgmtData_currArrayIndex++;
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 70;
			} else 			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 70;
			} else 			if ( xmldsigKeyInfoType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 8);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigKeyInfoType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigKeyInfoType->ANY.characters, xmldsigKeyInfoType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 71;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 70:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}KeyName), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}KeyValue), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}RetrievalMethod), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509Data), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}PGPData), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SPKIData), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}MgmtData), START_ELEMENT_GENERIC, END_ELEMENT, CHARACTERS_GENERIC[STRING]] */
			if (xmldsigKeyInfoType_KeyName_currArrayIndex < xmldsigKeyInfoType->KeyName.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 0);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[STRING]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						/* encode string as string table miss (+2 len)*/
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigKeyInfoType->KeyName.array[xmldsigKeyInfoType_KeyName_currArrayIndex].charactersLen + 2));
						if (errn == 0) {
							errn = encodeCharacters(stream, xmldsigKeyInfoType->KeyName.array[xmldsigKeyInfoType_KeyName_currArrayIndex].characters, xmldsigKeyInfoType->KeyName.array[xmldsigKeyInfoType_KeyName_currArrayIndex].charactersLen);
							xmldsigKeyInfoType_KeyName_currArrayIndex++;
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_KeyValue_currArrayIndex < xmldsigKeyInfoType->KeyValue.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 1);
				if(errn == 0) {
					errn = encode_xmldsigKeyValueType(stream, &xmldsigKeyInfoType->KeyValue.array [xmldsigKeyInfoType_KeyValue_currArrayIndex++]);
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_RetrievalMethod_currArrayIndex < xmldsigKeyInfoType->RetrievalMethod.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 2);
				if(errn == 0) {
					errn = encode_xmldsigRetrievalMethodType(stream, &xmldsigKeyInfoType->RetrievalMethod.array [xmldsigKeyInfoType_RetrievalMethod_currArrayIndex++]);
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_X509Data_currArrayIndex < xmldsigKeyInfoType->X509Data.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 3);
				if(errn == 0) {
					errn = encode_xmldsigX509DataType(stream, &xmldsigKeyInfoType->X509Data.array [xmldsigKeyInfoType_X509Data_currArrayIndex++]);
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_PGPData_currArrayIndex < xmldsigKeyInfoType->PGPData.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 4);
				if(errn == 0) {
					errn = encode_xmldsigPGPDataType(stream, &xmldsigKeyInfoType->PGPData.array [xmldsigKeyInfoType_PGPData_currArrayIndex++]);
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_SPKIData_currArrayIndex < xmldsigKeyInfoType->SPKIData.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 5);
				if(errn == 0) {
					errn = encode_xmldsigSPKIDataType(stream, &xmldsigKeyInfoType->SPKIData.array [xmldsigKeyInfoType_SPKIData_currArrayIndex++]);
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_MgmtData_currArrayIndex < xmldsigKeyInfoType->MgmtData.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 6);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[STRING]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						/* encode string as string table miss (+2 len)*/
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigKeyInfoType->MgmtData.array[xmldsigKeyInfoType_MgmtData_currArrayIndex].charactersLen + 2));
						if (errn == 0) {
							errn = encodeCharacters(stream, xmldsigKeyInfoType->MgmtData.array[xmldsigKeyInfoType_MgmtData_currArrayIndex].characters, xmldsigKeyInfoType->MgmtData.array[xmldsigKeyInfoType_MgmtData_currArrayIndex].charactersLen);
							xmldsigKeyInfoType_MgmtData_currArrayIndex++;
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 70;
			} else 			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 70;
			} else 			if ( xmldsigKeyInfoType->ANY_isUsed == 0u || wcDone ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 8);
				if(errn == 0) {
					done = 1;
				}
				grammarID = 3;
			} else 			if ( xmldsigKeyInfoType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 9);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigKeyInfoType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigKeyInfoType->ANY.characters, xmldsigKeyInfoType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 70;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		case 71:
			/* Element[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}KeyName), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}KeyValue), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}RetrievalMethod), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509Data), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}PGPData), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SPKIData), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}MgmtData), START_ELEMENT_GENERIC, CHARACTERS_GENERIC[STRING]] */
			if (xmldsigKeyInfoType_KeyName_currArrayIndex < xmldsigKeyInfoType->KeyName.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 0);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[STRING]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						/* encode string as string table miss (+2 len)*/
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigKeyInfoType->KeyName.array[xmldsigKeyInfoType_KeyName_currArrayIndex].charactersLen + 2));
						if (errn == 0) {
							errn = encodeCharacters(stream, xmldsigKeyInfoType->KeyName.array[xmldsigKeyInfoType_KeyName_currArrayIndex].characters, xmldsigKeyInfoType->KeyName.array[xmldsigKeyInfoType_KeyName_currArrayIndex].charactersLen);
							xmldsigKeyInfoType_KeyName_currArrayIndex++;
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_KeyValue_currArrayIndex < xmldsigKeyInfoType->KeyValue.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 1);
				if(errn == 0) {
					errn = encode_xmldsigKeyValueType(stream, &xmldsigKeyInfoType->KeyValue.array [xmldsigKeyInfoType_KeyValue_currArrayIndex++]);
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_RetrievalMethod_currArrayIndex < xmldsigKeyInfoType->RetrievalMethod.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 2);
				if(errn == 0) {
					errn = encode_xmldsigRetrievalMethodType(stream, &xmldsigKeyInfoType->RetrievalMethod.array [xmldsigKeyInfoType_RetrievalMethod_currArrayIndex++]);
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_X509Data_currArrayIndex < xmldsigKeyInfoType->X509Data.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 3);
				if(errn == 0) {
					errn = encode_xmldsigX509DataType(stream, &xmldsigKeyInfoType->X509Data.array [xmldsigKeyInfoType_X509Data_currArrayIndex++]);
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_PGPData_currArrayIndex < xmldsigKeyInfoType->PGPData.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 4);
				if(errn == 0) {
					errn = encode_xmldsigPGPDataType(stream, &xmldsigKeyInfoType->PGPData.array [xmldsigKeyInfoType_PGPData_currArrayIndex++]);
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_SPKIData_currArrayIndex < xmldsigKeyInfoType->SPKIData.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 5);
				if(errn == 0) {
					errn = encode_xmldsigSPKIDataType(stream, &xmldsigKeyInfoType->SPKIData.array [xmldsigKeyInfoType_SPKIData_currArrayIndex++]);
				}
				grammarID = 70;
			} else 			if (xmldsigKeyInfoType_MgmtData_currArrayIndex < xmldsigKeyInfoType->MgmtData.arrayLen ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 6);
				if(errn == 0) {
					/* First(xsi:type)StartTag[CHARACTERS[STRING]] */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
					if(errn == 0) {
						/* encode string as string table miss (+2 len)*/
						errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigKeyInfoType->MgmtData.array[xmldsigKeyInfoType_MgmtData_currArrayIndex].charactersLen + 2));
						if (errn == 0) {
							errn = encodeCharacters(stream, xmldsigKeyInfoType->MgmtData.array[xmldsigKeyInfoType_MgmtData_currArrayIndex].characters, xmldsigKeyInfoType->MgmtData.array[xmldsigKeyInfoType_MgmtData_currArrayIndex].charactersLen);
							xmldsigKeyInfoType_MgmtData_currArrayIndex++;
						}
						/* valid EE */
						errn = encodeNBitUnsignedInteger(stream, 1, 0);
					}
				}
				grammarID = 70;
			} else 			if (1==0) {
				errn = EXI_UNSUPPORTED_EVENT_CODE_CHARACTERISTICS;
				grammarID = 70;
			} else 			if ( xmldsigKeyInfoType->ANY_isUsed == 1u ) {
				errn = encodeNBitUnsignedInteger(stream, 4, 8);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(xmldsigKeyInfoType->ANY.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, xmldsigKeyInfoType->ANY.characters, xmldsigKeyInfoType->ANY.charactersLen);
					}
				}
				wcDone = 1;
				grammarID = 71;
			} else {
				errn = EXI_ERROR_UNKOWN_EVENT;
			}
			break;
		default:
			errn = EXI_ERROR_UNKOWN_GRAMMAR_ID;
			break;
		}
		if(errn) {
			done = 1;
		}
	}
	return errn;
}



int encode_xmldsigExiDocument(bitstream_t* stream, struct xmldsigEXIDocument* exiDoc) {
	errn = writeEXIHeader(stream);

	if(errn == 0) {
		/* DocContent[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}CanonicalizationMethod), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}DSAKeyValue), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}DigestMethod), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}DigestValue), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}KeyInfo), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}KeyName), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}KeyValue), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Manifest), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}MgmtData), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Object), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}PGPData), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}RSAKeyValue), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Reference), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}RetrievalMethod), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SPKIData), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Signature), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignatureMethod), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignatureProperties), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignatureProperty), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignatureValue), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignedInfo), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Transform), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Transforms), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509Data), START_ELEMENT_GENERIC] */
		if ( exiDoc->CanonicalizationMethod_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}CanonicalizationMethod) */
			errn = encodeNBitUnsignedInteger(stream, 5, 0);
			if(errn == 0) {
				errn = encode_xmldsigCanonicalizationMethodType(stream, &exiDoc->CanonicalizationMethod );
			}
		} else if ( exiDoc->DSAKeyValue_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}DSAKeyValue) */
			errn = encodeNBitUnsignedInteger(stream, 5, 1);
			if(errn == 0) {
				errn = encode_xmldsigDSAKeyValueType(stream, &exiDoc->DSAKeyValue );
			}
		} else if ( exiDoc->DigestMethod_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}DigestMethod) */
			errn = encodeNBitUnsignedInteger(stream, 5, 2);
			if(errn == 0) {
				errn = encode_xmldsigDigestMethodType(stream, &exiDoc->DigestMethod );
			}
		} else if ( exiDoc->DigestValue_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}DigestValue) */
			errn = encodeNBitUnsignedInteger(stream, 5, 3);
			if(errn == 0) {
				/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiDoc->DigestValue.bytesLen));
					if (errn == 0) {
						errn = encodeBytes(stream, exiDoc->DigestValue.bytes, exiDoc->DigestValue.bytesLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiDoc->KeyInfo_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}KeyInfo) */
			errn = encodeNBitUnsignedInteger(stream, 5, 4);
			if(errn == 0) {
				errn = encode_xmldsigKeyInfoType(stream, &exiDoc->KeyInfo );
			}
		} else if ( exiDoc->KeyName_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}KeyName) */
			errn = encodeNBitUnsignedInteger(stream, 5, 5);
			if(errn == 0) {
				/* First(xsi:type)StartTag[CHARACTERS[STRING]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiDoc->KeyName.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, exiDoc->KeyName.characters, exiDoc->KeyName.charactersLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiDoc->KeyValue_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}KeyValue) */
			errn = encodeNBitUnsignedInteger(stream, 5, 6);
			if(errn == 0) {
				errn = encode_xmldsigKeyValueType(stream, &exiDoc->KeyValue );
			}
		} else if ( exiDoc->Manifest_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Manifest) */
			errn = encodeNBitUnsignedInteger(stream, 5, 7);
			if(errn == 0) {
				errn = encode_xmldsigManifestType(stream, &exiDoc->Manifest );
			}
		} else if ( exiDoc->MgmtData_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}MgmtData) */
			errn = encodeNBitUnsignedInteger(stream, 5, 8);
			if(errn == 0) {
				/* First(xsi:type)StartTag[CHARACTERS[STRING]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiDoc->MgmtData.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, exiDoc->MgmtData.characters, exiDoc->MgmtData.charactersLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiDoc->Object_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Object) */
			errn = encodeNBitUnsignedInteger(stream, 5, 9);
			if(errn == 0) {
				errn = encode_xmldsigObjectType(stream, &exiDoc->Object );
			}
		} else if ( exiDoc->PGPData_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}PGPData) */
			errn = encodeNBitUnsignedInteger(stream, 5, 10);
			if(errn == 0) {
				errn = encode_xmldsigPGPDataType(stream, &exiDoc->PGPData );
			}
		} else if ( exiDoc->RSAKeyValue_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}RSAKeyValue) */
			errn = encodeNBitUnsignedInteger(stream, 5, 11);
			if(errn == 0) {
				errn = encode_xmldsigRSAKeyValueType(stream, &exiDoc->RSAKeyValue );
			}
		} else if ( exiDoc->Reference_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Reference) */
			errn = encodeNBitUnsignedInteger(stream, 5, 12);
			if(errn == 0) {
				errn = encode_xmldsigReferenceType(stream, &exiDoc->Reference );
			}
		} else if ( exiDoc->RetrievalMethod_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}RetrievalMethod) */
			errn = encodeNBitUnsignedInteger(stream, 5, 13);
			if(errn == 0) {
				errn = encode_xmldsigRetrievalMethodType(stream, &exiDoc->RetrievalMethod );
			}
		} else if ( exiDoc->SPKIData_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SPKIData) */
			errn = encodeNBitUnsignedInteger(stream, 5, 14);
			if(errn == 0) {
				errn = encode_xmldsigSPKIDataType(stream, &exiDoc->SPKIData );
			}
		} else if ( exiDoc->Signature_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Signature) */
			errn = encodeNBitUnsignedInteger(stream, 5, 15);
			if(errn == 0) {
				errn = encode_xmldsigSignatureType(stream, &exiDoc->Signature );
			}
		} else if ( exiDoc->SignatureMethod_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignatureMethod) */
			errn = encodeNBitUnsignedInteger(stream, 5, 16);
			if(errn == 0) {
				errn = encode_xmldsigSignatureMethodType(stream, &exiDoc->SignatureMethod );
			}
		} else if ( exiDoc->SignatureProperties_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignatureProperties) */
			errn = encodeNBitUnsignedInteger(stream, 5, 17);
			if(errn == 0) {
				errn = encode_xmldsigSignaturePropertiesType(stream, &exiDoc->SignatureProperties );
			}
		} else if ( exiDoc->SignatureProperty_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignatureProperty) */
			errn = encodeNBitUnsignedInteger(stream, 5, 18);
			if(errn == 0) {
				errn = encode_xmldsigSignaturePropertyType(stream, &exiDoc->SignatureProperty );
			}
		} else if ( exiDoc->SignatureValue_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignatureValue) */
			errn = encodeNBitUnsignedInteger(stream, 5, 19);
			if(errn == 0) {
				errn = encode_xmldsigSignatureValueType(stream, &exiDoc->SignatureValue );
			}
		} else if ( exiDoc->SignedInfo_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignedInfo) */
			errn = encodeNBitUnsignedInteger(stream, 5, 20);
			if(errn == 0) {
				errn = encode_xmldsigSignedInfoType(stream, &exiDoc->SignedInfo );
			}
		} else if ( exiDoc->Transform_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Transform) */
			errn = encodeNBitUnsignedInteger(stream, 5, 21);
			if(errn == 0) {
				errn = encode_xmldsigTransformType(stream, &exiDoc->Transform );
			}
		} else if ( exiDoc->Transforms_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Transforms) */
			errn = encodeNBitUnsignedInteger(stream, 5, 22);
			if(errn == 0) {
				errn = encode_xmldsigTransformsType(stream, &exiDoc->Transforms );
			}
		} else if ( exiDoc->X509Data_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509Data) */
			errn = encodeNBitUnsignedInteger(stream, 5, 23);
			if(errn == 0) {
				errn = encode_xmldsigX509DataType(stream, &exiDoc->X509Data );
			}
		} else {
			errn = EXI_ERROR_UNKOWN_EVENT;
		}

	}

	if(errn == 0) {
		/* flush any pending bits */
		errn = encodeFinish(stream);
	}

	return errn;
}

#if DEPLOY_XMLDSIG_CODEC_FRAGMENT == SUPPORT_YES
int encode_xmldsigExiFragment(bitstream_t* stream, struct xmldsigEXIFragment* exiFrag) {
	errn = writeEXIHeader(stream);

	if(errn == 0) {
		/* FragmentContent[START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}CanonicalizationMethod), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}DSAKeyValue), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}DigestMethod), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}DigestValue), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Exponent), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}G), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}HMACOutputLength), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}J), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}KeyInfo), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}KeyName), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}KeyValue), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Manifest), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}MgmtData), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Modulus), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Object), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}P), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}PGPData), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}PGPKeyID), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}PGPKeyPacket), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}PgenCounter), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Q), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}RSAKeyValue), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Reference), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}RetrievalMethod), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SPKIData), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SPKISexp), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Seed), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Signature), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignatureMethod), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignatureProperties), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignatureProperty), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignatureValue), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignedInfo), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Transform), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Transforms), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509CRL), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509Certificate), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509Data), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509IssuerName), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509IssuerSerial), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509SKI), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509SerialNumber), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509SubjectName), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}XPath), START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Y), START_ELEMENT_GENERIC, END_DOCUMENT] */
		if ( exiFrag->CanonicalizationMethod_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}CanonicalizationMethod) */
			errn = encodeNBitUnsignedInteger(stream, 6, 0);
			if(errn == 0) {
				errn = encode_xmldsigCanonicalizationMethodType(stream, &exiFrag->CanonicalizationMethod );
			}
		} else if ( exiFrag->DSAKeyValue_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}DSAKeyValue) */
			errn = encodeNBitUnsignedInteger(stream, 6, 1);
			if(errn == 0) {
				errn = encode_xmldsigDSAKeyValueType(stream, &exiFrag->DSAKeyValue );
			}
		} else if ( exiFrag->DigestMethod_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}DigestMethod) */
			errn = encodeNBitUnsignedInteger(stream, 6, 2);
			if(errn == 0) {
				errn = encode_xmldsigDigestMethodType(stream, &exiFrag->DigestMethod );
			}
		} else if ( exiFrag->DigestValue_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}DigestValue) */
			errn = encodeNBitUnsignedInteger(stream, 6, 3);
			if(errn == 0) {
				/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiFrag->DigestValue.bytesLen));
					if (errn == 0) {
						errn = encodeBytes(stream, exiFrag->DigestValue.bytes, exiFrag->DigestValue.bytesLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiFrag->Exponent_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Exponent) */
			errn = encodeNBitUnsignedInteger(stream, 6, 4);
			if(errn == 0) {
				/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiFrag->Exponent.bytesLen));
					if (errn == 0) {
						errn = encodeBytes(stream, exiFrag->Exponent.bytes, exiFrag->Exponent.bytesLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiFrag->G_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}G) */
			errn = encodeNBitUnsignedInteger(stream, 6, 5);
			if(errn == 0) {
				/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiFrag->G.bytesLen));
					if (errn == 0) {
						errn = encodeBytes(stream, exiFrag->G.bytes, exiFrag->G.bytesLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiFrag->HMACOutputLength_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}HMACOutputLength) */
			errn = encodeNBitUnsignedInteger(stream, 6, 6);
			if(errn == 0) {
				/* FirstStartTag[CHARACTERS[INTEGER]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encodeInteger64(stream, exiFrag->HMACOutputLength);
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiFrag->J_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}J) */
			errn = encodeNBitUnsignedInteger(stream, 6, 7);
			if(errn == 0) {
				/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiFrag->J.bytesLen));
					if (errn == 0) {
						errn = encodeBytes(stream, exiFrag->J.bytes, exiFrag->J.bytesLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiFrag->KeyInfo_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}KeyInfo) */
			errn = encodeNBitUnsignedInteger(stream, 6, 8);
			if(errn == 0) {
				errn = encode_xmldsigKeyInfoType(stream, &exiFrag->KeyInfo );
			}
		} else if ( exiFrag->KeyName_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}KeyName) */
			errn = encodeNBitUnsignedInteger(stream, 6, 9);
			if(errn == 0) {
				/* First(xsi:type)StartTag[CHARACTERS[STRING]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiFrag->KeyName.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, exiFrag->KeyName.characters, exiFrag->KeyName.charactersLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiFrag->KeyValue_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}KeyValue) */
			errn = encodeNBitUnsignedInteger(stream, 6, 10);
			if(errn == 0) {
				errn = encode_xmldsigKeyValueType(stream, &exiFrag->KeyValue );
			}
		} else if ( exiFrag->Manifest_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Manifest) */
			errn = encodeNBitUnsignedInteger(stream, 6, 11);
			if(errn == 0) {
				errn = encode_xmldsigManifestType(stream, &exiFrag->Manifest );
			}
		} else if ( exiFrag->MgmtData_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}MgmtData) */
			errn = encodeNBitUnsignedInteger(stream, 6, 12);
			if(errn == 0) {
				/* First(xsi:type)StartTag[CHARACTERS[STRING]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiFrag->MgmtData.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, exiFrag->MgmtData.characters, exiFrag->MgmtData.charactersLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiFrag->Modulus_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Modulus) */
			errn = encodeNBitUnsignedInteger(stream, 6, 13);
			if(errn == 0) {
				/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiFrag->Modulus.bytesLen));
					if (errn == 0) {
						errn = encodeBytes(stream, exiFrag->Modulus.bytes, exiFrag->Modulus.bytesLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiFrag->Object_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Object) */
			errn = encodeNBitUnsignedInteger(stream, 6, 14);
			if(errn == 0) {
				errn = encode_xmldsigObjectType(stream, &exiFrag->Object );
			}
		} else if ( exiFrag->P_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}P) */
			errn = encodeNBitUnsignedInteger(stream, 6, 15);
			if(errn == 0) {
				/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiFrag->P.bytesLen));
					if (errn == 0) {
						errn = encodeBytes(stream, exiFrag->P.bytes, exiFrag->P.bytesLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiFrag->PGPData_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}PGPData) */
			errn = encodeNBitUnsignedInteger(stream, 6, 16);
			if(errn == 0) {
				errn = encode_xmldsigPGPDataType(stream, &exiFrag->PGPData );
			}
		} else if ( exiFrag->PGPKeyID_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}PGPKeyID) */
			errn = encodeNBitUnsignedInteger(stream, 6, 17);
			if(errn == 0) {
				/* First(xsi:type)StartTag[CHARACTERS[BINARY_BASE64]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiFrag->PGPKeyID.bytesLen));
					if (errn == 0) {
						errn = encodeBytes(stream, exiFrag->PGPKeyID.bytes, exiFrag->PGPKeyID.bytesLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiFrag->PGPKeyPacket_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}PGPKeyPacket) */
			errn = EXI_UNSUPPORTED_FRAGMENT_ELEMENT; /* overlapping name PGPKeyPacket */
		} else if ( exiFrag->PgenCounter_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}PgenCounter) */
			errn = encodeNBitUnsignedInteger(stream, 6, 19);
			if(errn == 0) {
				/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiFrag->PgenCounter.bytesLen));
					if (errn == 0) {
						errn = encodeBytes(stream, exiFrag->PgenCounter.bytes, exiFrag->PgenCounter.bytesLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiFrag->Q_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Q) */
			errn = encodeNBitUnsignedInteger(stream, 6, 20);
			if(errn == 0) {
				/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiFrag->Q.bytesLen));
					if (errn == 0) {
						errn = encodeBytes(stream, exiFrag->Q.bytes, exiFrag->Q.bytesLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiFrag->RSAKeyValue_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}RSAKeyValue) */
			errn = encodeNBitUnsignedInteger(stream, 6, 21);
			if(errn == 0) {
				errn = encode_xmldsigRSAKeyValueType(stream, &exiFrag->RSAKeyValue );
			}
		} else if ( exiFrag->Reference_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Reference) */
			errn = encodeNBitUnsignedInteger(stream, 6, 22);
			if(errn == 0) {
				errn = encode_xmldsigReferenceType(stream, &exiFrag->Reference );
			}
		} else if ( exiFrag->RetrievalMethod_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}RetrievalMethod) */
			errn = encodeNBitUnsignedInteger(stream, 6, 23);
			if(errn == 0) {
				errn = encode_xmldsigRetrievalMethodType(stream, &exiFrag->RetrievalMethod );
			}
		} else if ( exiFrag->SPKIData_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SPKIData) */
			errn = encodeNBitUnsignedInteger(stream, 6, 24);
			if(errn == 0) {
				errn = encode_xmldsigSPKIDataType(stream, &exiFrag->SPKIData );
			}
		} else if ( exiFrag->SPKISexp_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SPKISexp) */
			errn = encodeNBitUnsignedInteger(stream, 6, 25);
			if(errn == 0) {
				/* First(xsi:type)StartTag[CHARACTERS[BINARY_BASE64]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiFrag->SPKISexp.bytesLen));
					if (errn == 0) {
						errn = encodeBytes(stream, exiFrag->SPKISexp.bytes, exiFrag->SPKISexp.bytesLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiFrag->Seed_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Seed) */
			errn = encodeNBitUnsignedInteger(stream, 6, 26);
			if(errn == 0) {
				/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiFrag->Seed.bytesLen));
					if (errn == 0) {
						errn = encodeBytes(stream, exiFrag->Seed.bytes, exiFrag->Seed.bytesLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiFrag->Signature_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Signature) */
			errn = encodeNBitUnsignedInteger(stream, 6, 27);
			if(errn == 0) {
				errn = encode_xmldsigSignatureType(stream, &exiFrag->Signature );
			}
		} else if ( exiFrag->SignatureMethod_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignatureMethod) */
			errn = encodeNBitUnsignedInteger(stream, 6, 28);
			if(errn == 0) {
				errn = encode_xmldsigSignatureMethodType(stream, &exiFrag->SignatureMethod );
			}
		} else if ( exiFrag->SignatureProperties_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignatureProperties) */
			errn = encodeNBitUnsignedInteger(stream, 6, 29);
			if(errn == 0) {
				errn = encode_xmldsigSignaturePropertiesType(stream, &exiFrag->SignatureProperties );
			}
		} else if ( exiFrag->SignatureProperty_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignatureProperty) */
			errn = encodeNBitUnsignedInteger(stream, 6, 30);
			if(errn == 0) {
				errn = encode_xmldsigSignaturePropertyType(stream, &exiFrag->SignatureProperty );
			}
		} else if ( exiFrag->SignatureValue_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignatureValue) */
			errn = encodeNBitUnsignedInteger(stream, 6, 31);
			if(errn == 0) {
				errn = encode_xmldsigSignatureValueType(stream, &exiFrag->SignatureValue );
			}
		} else if ( exiFrag->SignedInfo_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}SignedInfo) */
			errn = encodeNBitUnsignedInteger(stream, 6, 32);
			if(errn == 0) {
				errn = encode_xmldsigSignedInfoType(stream, &exiFrag->SignedInfo );
			}
		} else if ( exiFrag->Transform_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Transform) */
			errn = encodeNBitUnsignedInteger(stream, 6, 33);
			if(errn == 0) {
				errn = encode_xmldsigTransformType(stream, &exiFrag->Transform );
			}
		} else if ( exiFrag->Transforms_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Transforms) */
			errn = encodeNBitUnsignedInteger(stream, 6, 34);
			if(errn == 0) {
				errn = encode_xmldsigTransformsType(stream, &exiFrag->Transforms );
			}
		} else if ( exiFrag->X509CRL_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509CRL) */
			errn = encodeNBitUnsignedInteger(stream, 6, 35);
			if(errn == 0) {
				/* First(xsi:type)StartTag[CHARACTERS[BINARY_BASE64]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiFrag->X509CRL.bytesLen));
					if (errn == 0) {
						errn = encodeBytes(stream, exiFrag->X509CRL.bytes, exiFrag->X509CRL.bytesLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiFrag->X509Certificate_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509Certificate) */
			errn = encodeNBitUnsignedInteger(stream, 6, 36);
			if(errn == 0) {
				/* First(xsi:type)StartTag[CHARACTERS[BINARY_BASE64]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiFrag->X509Certificate.bytesLen));
					if (errn == 0) {
						errn = encodeBytes(stream, exiFrag->X509Certificate.bytes, exiFrag->X509Certificate.bytesLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiFrag->X509Data_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509Data) */
			errn = encodeNBitUnsignedInteger(stream, 6, 37);
			if(errn == 0) {
				errn = encode_xmldsigX509DataType(stream, &exiFrag->X509Data );
			}
		} else if ( exiFrag->X509IssuerName_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509IssuerName) */
			errn = encodeNBitUnsignedInteger(stream, 6, 38);
			if(errn == 0) {
				/* First(xsi:type)StartTag[CHARACTERS[STRING]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiFrag->X509IssuerName.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, exiFrag->X509IssuerName.characters, exiFrag->X509IssuerName.charactersLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiFrag->X509IssuerSerial_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509IssuerSerial) */
			errn = encodeNBitUnsignedInteger(stream, 6, 39);
			if(errn == 0) {
				errn = encode_xmldsigX509IssuerSerialType(stream, &exiFrag->X509IssuerSerial );
			}
		} else if ( exiFrag->X509SKI_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509SKI) */
			errn = encodeNBitUnsignedInteger(stream, 6, 40);
			if(errn == 0) {
				/* First(xsi:type)StartTag[CHARACTERS[BINARY_BASE64]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiFrag->X509SKI.bytesLen));
					if (errn == 0) {
						errn = encodeBytes(stream, exiFrag->X509SKI.bytes, exiFrag->X509SKI.bytesLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiFrag->X509SerialNumber_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509SerialNumber) */
			errn = encodeNBitUnsignedInteger(stream, 6, 41);
			if(errn == 0) {
				/* First(xsi:type)StartTag[CHARACTERS[INTEGER]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encodeInteger64(stream, exiFrag->X509SerialNumber);
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiFrag->X509SubjectName_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}X509SubjectName) */
			errn = encodeNBitUnsignedInteger(stream, 6, 42);
			if(errn == 0) {
				/* First(xsi:type)StartTag[CHARACTERS[STRING]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiFrag->X509SubjectName.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, exiFrag->X509SubjectName.characters, exiFrag->X509SubjectName.charactersLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiFrag->XPath_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}XPath) */
			errn = encodeNBitUnsignedInteger(stream, 6, 43);
			if(errn == 0) {
				/* First(xsi:type)StartTag[CHARACTERS[STRING]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					/* encode string as string table miss (+2 len)*/
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiFrag->XPath.charactersLen + 2));
					if (errn == 0) {
						errn = encodeCharacters(stream, exiFrag->XPath.characters, exiFrag->XPath.charactersLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else if ( exiFrag->Y_isUsed == 1u ) { 
			/* START_ELEMENT({http://www.w3.org/2000/09/xmldsig#}Y) */
			errn = encodeNBitUnsignedInteger(stream, 6, 44);
			if(errn == 0) {
				/* FirstStartTag[CHARACTERS[BINARY_BASE64]] */
				errn = encodeNBitUnsignedInteger(stream, 1, 0);
				if(errn == 0) {
					errn = encodeUnsignedInteger16(stream, (uint16_t)(exiFrag->Y.bytesLen));
					if (errn == 0) {
						errn = encodeBytes(stream, exiFrag->Y.bytes, exiFrag->Y.bytesLen);
					}
					/* valid EE */
					errn = encodeNBitUnsignedInteger(stream, 1, 0);
				}
			}
		} else {
			errn = EXI_ERROR_UNKOWN_EVENT;
		}
	}
	if(errn == 0) {
		/* EndDocument */
		errn = encodeNBitUnsignedInteger(stream, 6, 46);
	}


	if(errn == 0) {
		/* flush any pending bits */
		errn = encodeFinish(stream);
	}

	return errn;
}
#endif /* DEPLOY_XMLDSIG_CODEC_FRAGMENT */


#endif /* DEPLOY_XMLDSIG_CODEC */

#endif

